// pages/driver/wallet/wallet.js
const handler = require("../../../utils/function.js");
const app = getApp();
var api = require("../../../api.js");
Page({
    /**
     * 页面的初始数据
     */
    data: {
        imgs: handler.userImg,
        img: handler.driverImg,
        TodayIncome: 0, //今日收入
        Spending: 0, //总支出
        Income: 0, //总收入
        Refund: 0, //退款
        balance: 0, //余额
        list: {},
        page:1
    },
    intoPageHandler: function(e) {
        
        handler.intoPageHandler(e.currentTarget.dataset.skip);
    },
    //获取时间
    bindTimeChange:function(e){
      console.log(e)
      let that=this;
      wx.showLoading({})
      this.setData({ page: 1 })
      app.request({
        url: api.wallet_log.index,
        method: 'post',
        data:{
          start_time:e.detail.value,
          page:1
        },
        success:function(rs){
          wx.hideLoading();
            console.log(rs,'22222222222222222')
          that.setData({
            Spending: rs.data.conclusion.Spending, //总支出
            Income: rs.data.conclusion.Income, //总收入
            Refund: rs.data.conclusion.Refund, //退款
            balance: rs.data.user.price, //余额
            list: rs.data.wallet.data,
          });
        },
      })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        console.log('提现',options)
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
      this.getData()
    },
    getData:function(){
      var that = this;
      wx.showLoading({})
      app.request({
        url: api.wallet.wallet,
        method: 'post',
        data: {},
        success: function (rs) {
          wx.hideLoading();
          console.log(rs)
          if (rs.code == 1) {
            that.setData({
              TodayIncome: rs.data.user.TodayIncome, //今日收入
              TodayIncome: rs.data.user.TodayIncome, //今日收入
              Spending: rs.data.conclusion.Spending, //总支出
              Income: rs.data.conclusion.Income, //总收入
              Refund: rs.data.conclusion.Refund, //退款
              balance: rs.data.user.price, //余额
              list: rs.data.wallet.data,
            });
          }
        }
      })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
      console.log(e)
      let that = this;
      wx.showLoading({
      })
      var { page } = this.data;
      page++;
      this.setData({ page: page });
      app.request({
        url: api.wallet_log.index,
        method: 'post',
        data: {
          start_time: e.detail.value,
          page: that.data.page
        },
        success: function (rs) {
          wx.hideLoading();
          console.log(rs, '22222222222222222')
          that.setData({
            Spending: rs.data.conclusion.Spending, //总支出
            Income: rs.data.conclusion.Income, //总收入
            Refund: rs.data.conclusion.Refund, //退款
            balance: rs.data.user.price, //余额
            list: rs.data.wallet.data,
          });
        },
      })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {}
})